package com.liuzhongni.wahahanews.headlineclass;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by dllo on 16/1/12.
 */
public class MyMemoryCache implements ImageLoader.ImageCache {

    private LruCache<String,Bitmap> cache;

    public MyMemoryCache() {
       int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
        int cacheSize =  (maxMemory/4);
        cache = new LruCache<String,Bitmap>(cacheSize){
            @Override
            protected int sizeOf(String url, Bitmap bitmap) {
                return bitmap.getRowBytes()*bitmap.getHeight()/1024;
            }
        };


    }

    @Override
    public Bitmap getBitmap(String url) {
        return cache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        cache.put(url,bitmap);
    }
}
